<?php include "./pc/view/my_header.inc.htm"; ?>

<form action="my-password.htm" method="post" id="my_password_form">
	<div class="panel_body margin">
		<dl class="row form">
			<dt class="col-3 right">旧密码：</dt><dd class="col-7"><input type="password" name="password" class="small" /></dd>
			<dt class="col-3 right">新密码：</dt><dd class="col-7"><input type="password" name="newpassword" class="small" /></dd>
			<dt class="col-3 right">重复密码：</dt><dd class="col-7"><input type="password" name="newpassword2" class="small" /></dd>
			<dt class="col-3 right"></dt><dd class="col-7"><button class="middle blue" type="submit" loading-text="正在提交...">确定</button></dd>
		</dl>
	</div>
</form>

<?php include "./pc/view/my_footer.inc.htm"; ?>

<script>

var jform = $('#my_password_form');
var jpassword = jform.find('input[name="password"]');
var jnewpassword = jform.find('input[name="newpassword"]');
var jnewpassword2 = jform.find('input[name="newpassword2"]');
var jsubmit = jform.find('button[type="submit"]');
jform.off('submit').on('submit', function() {
	if(!jpassword.val()) {
		jpassword.popover('请输入旧密码').focus();
		return false;
	} else if(!jnewpassword.val()) {
		jnewpassword.popover('请输入新密码').focus();
		return false;
	} else if(jnewpassword.val() != jnewpassword2.val()) {
		jnewpassword2.popover('两次输入的密码不一致。').focus();
		return false;
	}
	var postdata = "password="+$.md5(jpassword.val())+"&newpassword="+$.md5(jnewpassword.val());
	jsubmit.button('loading');
	$.xpost(jform.attr('action'), postdata, function(code, message) {
		if(code == 0) {
			jsubmit.text(message);
			setTimeout(function() {jsubmit.button('reset');}, 2000);
			return;
		} else  if(code == 1) {
			jpassword.popover(message).focus();
		} else  if(code == 2) {
			jnewpassword.popover(message).focus();
		} else  if(code == 3) {
			jnewpassword2.popover(message).focus();
		} else {
			$.alert(message);
		}
		jsubmit.button('reset');
	});
	return false;
});

$('#my_profile_menu').find('a').eq(1).class_active();

</script>